package com.cyx.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class DispatchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //这样请求转发路径不会变化
        //RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/hello");
        //dispatcher.forward(req,resp);

        //通过请求直接转发,上面通过上下文方式比较少用
        req.getRequestDispatcher("/hello").forward(req,resp);
    }

}
